/*
 *  Copyright 2010 dmakariev.
 *
 */
package org.deltaset.faces.upload;

import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;

/**
 *
 * @author dmakariev
 */
class FileRequest {

    private final Map<String, List<DsFileItem>> fileParameterMap;

    @SuppressWarnings("unchecked")
    FileRequest() {
        this.fileParameterMap = Collections.EMPTY_MAP;
    }

    boolean isEmpty() {
        return this.fileParameterMap.isEmpty();
    }

    FileRequest(Map<String, List<DsFileItem>> fileParameterMap) {
        this.fileParameterMap = fileParameterMap;
    }

    Map<String, List<DsFileItem>> getFileParameterMap() {
        return Collections.unmodifiableMap(fileParameterMap);
    }

    Enumeration<String> getFileParameterNames() {
        return Collections.enumeration(fileParameterMap.keySet());
    }

    List<DsFileItem> getFileParameterValues(final String name) {
        if (fileParameterMap.containsKey(name)) {
            final List<DsFileItem> values = fileParameterMap.get(name);
            return values;
        } else {
            return null;
        }
    }

    DsFileItem getFileParameter(final String name) {
        if (fileParameterMap.containsKey(name)) {
            final List<DsFileItem> items = fileParameterMap.get(name);
            return items.get(0);
        } else {
            return null;
        }
    }
}
